﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using EFCore.Repositorys.DB;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers.DB
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class Db_ProductController : ControllerBase
    {
        private readonly IDb_ProductService db_ProductService;
        private readonly IMapper mapper;

        public Db_ProductController(IDb_ProductService db_ProductService,IMapper mapper)
        {
            this.db_ProductService = db_ProductService;
            this.mapper = mapper;
        }

        /// <summary>
        /// 分页条件查询产品信息
        /// </summary>
        /// <param name="proName"></param>
        /// <param name="typeCode"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult Get_Products(string? proName, string? typeCode, int currentPage, int pageSize)
        {
            return new JsonResult(db_ProductService.Get_Products(proName,typeCode,currentPage,pageSize));
        }

        /// <summary>
        /// 条件查询产品总数
        /// </summary>
        /// <param name="proName"></param>
        /// <param name="typeCode"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult ProductCount(string? proName, string? typeCode)
        {
            return new JsonResult(db_ProductService.ProductCount(proName,typeCode));
        }




        /// <summary>
        /// 查询产品信息--其他入库单
        /// </summary>
        /// <param name="procode"></param>
        /// <param name="Pro_type_code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public JsonResult Get_Products_Other(string ? procode, string ? Measure_id, int currentPage, int pageSize)
        {
           return new JsonResult(db_ProductService.Get_Products_Other(procode, Measure_id, currentPage, pageSize));
        }

        /// <summary>
        /// 查询产品信息-其他入库单-总数
        /// </summary>
        /// <param name="procode"></param>
        /// <param name="Pro_type_code"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public int ProductCount_Other(string ? procode, string ? Measure_id)
        {
            return db_ProductService.ProductCount_Other(procode, Measure_id);
        }

        /// <summary>
        /// 添加产品基础信息
        /// </summary>
        /// <param name="db_ProductAddDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<JsonResult> ProductAddAsync(Db_ProductAddDto db_ProductAddDto)
        {
            return new JsonResult(await db_ProductService.ProductAddAsync(db_ProductAddDto));
        }

        /// <summary>
        /// 验证序号是不是唯一
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="proId"></param>
        /// <returns></returns>
        [HttpGet]
        public JsonResult CheckSortUnique(int sort, int proId)
        {
            return new JsonResult(db_ProductService.CheckSortUnique(sort,proId));
        }

        /// <summary>
        /// 逻辑删除产品信息
        /// </summary>
        /// <param name="db_ProductDelDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> ProductDelAsync(Db_ProductDelDto db_ProductDelDto)
        {
            return new JsonResult(await db_ProductService.ProductDelAsync(db_ProductDelDto));
        }

        /// <summary>
        /// 根据编号查询对应的产品信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetDb_ProductByCode(string code)
        {
            return new JsonResult(await db_ProductService.GetDb_ProductByCode(code));
        }

        /// <summary>
        /// 修改产品信息
        /// </summary>
        /// <param name="db_ProductUpdateDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<JsonResult> ProductUpdateAsync(Db_ProductUpdateDto db_ProductUpdateDto)
        {
            return new JsonResult(await db_ProductService.ProductUpdateAsync(db_ProductUpdateDto));
        }
    }
}
